import java.math.BigDecimal;

public class DmsTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 02-09 14:21:03.495: I/System.out(24639): 39.128605475823086
		// 02-09 14:21:03.496: I/System.out(24639): 117.18468227783839
		// 02-09 14:21:03.499: I/System.out(24639): 39/1,6/1,47887/1000
		// 02-09 14:21:03.499: I/System.out(24639): 117/1,9/1,31410/1000
		// 02-09 14:48:45.853: I/System.out(31021): 39/1,6/1,47887/1000
		// 02-09 14:48:45.853: I/System.out(31021): 117/1,9/1,31410/1000
		// 02-09 14:48:45.854: I/System.out(31021): 39.113301944444444
		// 02-09 14:48:45.856: I/System.out(31021): 117.158725

		// 0.128605475823086 * 60
		System.out.println(decimalToDMS(39.113301944444444));
		 System.out.println(decimalToDMS(117.158725));
		// System.out.println(convertToDegree("39/1,6/1,47887/1000"));
		// System.out.println(convertToDegree("117/1,9/1,31410/1000"));
	}

	/**
	 * 地理位置转换
	 * 
	 * @param num
	 * @return
	 */
	public static String decimalToDMS(double num) {
		int du = (int) Math.floor(Math.abs(num)); // 获取整数部分
		double temp = getdPoint(Math.abs(num)) * 60;
//		System.out.println(getdPoint(Math.abs(num)));
//		System.out.println(temp);
		int fen = (int) Math.floor(temp); // 获取整数部分
//		System.out.println(fen);
		double miao = getdPoint(temp) * 60;
//		System.out.println(miao);
		// if (num < 0)
		// return du + "/1," + fen + "/1," + miao * 1000 + "/1000";
		return du + "/1," + fen + "/1," + miao * 1000 + "/1000";

	}

	public static String decimalToDMS1(double num) {
		return "";
	}

	/** 获取小数部分 */
	public static double getdPoint(double num) {
		double d = num;
		int fInt = (int) d;
		BigDecimal b1 = new BigDecimal(Double.toString(d));
		BigDecimal b2 = new BigDecimal(Integer.toString(fInt));
		double dPoint = b1.subtract(b2).doubleValue();
		// double dPoint = b1.subtract(b2).floatValue();
		return dPoint;
	}

	private static Double convertToDegree(String stringDMS) {
		String[] DMS = stringDMS.split(",", 3);

		String[] stringD = DMS[0].split("/", 2);
		Double D0 = Double.valueOf(stringD[0]);
		Double D1 = Double.valueOf(stringD[1]);
		Double doubleD = D0 / D1;

		String[] stringM = DMS[1].split("/", 2);
		Double M0 = Double.valueOf(stringM[0]);
		Double M1 = Double.valueOf(stringM[1]);
		Double doubleM = M0 / M1;

		String[] stringS = DMS[2].split("/", 2);
		Double S0 = Double.valueOf(stringS[0]);
		Double S1 = Double.valueOf(stringS[1]);
		Double doubleS = S0 / S1;

		return doubleD + doubleM / 60 + doubleS / 3600;
	}
}
